﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace CallApi.Response
{
    public class ResultResponse
    {

        #region .ctor

        /// <summary>
        /// .ctor
        /// </summary>
        public ResultResponse()
        {
        }

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="state">状态</param>
        public ResultResponse(int state)
            : this()
        {
            Code = state;
        }

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="state">状态</param>
        /// <param name="msg">备注</param>
        public ResultResponse(int state, string msg)
            : this(state)
        {
            Message = msg;
        }

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="state">状态</param>
        /// <param name="msg">备注</param>
        /// <param name="data">内容</param>
        public ResultResponse(int state, string msg, object data)
            : this(state, msg)
        {
            Data = data;
        }

        #endregion .ctor

        /// <summary>
        /// 结果返回状态
        /// 0失败1成功
        /// </summary>
        [JsonProperty(PropertyName = "code")]
        public int Code { get; set; }

        /// <summary>
        /// 附加说明
        /// </summary>
        [JsonProperty(PropertyName = "message")]
        public string Message { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        [JsonProperty(PropertyName = "data")]
        public object Data { get; set; }



        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg">失败信息</param>
        /// <returns>ajax结果</returns>
        public static ResultResponse Failed(string msg)
        {
            return new ResultResponse(0, msg);
        }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="msg">备注</param>
        /// <returns>ajax结果</returns>
        public static ResultResponse Success(object data, string msg = "")
        {
            return new ResultResponse(1, msg, data);
        }


    }
}
